package com.taiji.web.controller.workOrder;

import com.taiji.common.core.domain.AjaxResult;
import com.taiji.workOrder.domain.ServerMonitorData;
import com.taiji.workOrder.dto.ServerMonitorDataDTO;
import com.taiji.workOrder.dto.ServerVO;
import com.taiji.workOrder.service.IMonitorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author -1
 * @since 2023/08/08 15:54
 * description:
 */

@Api(tags="对接运维驾驶舱监控数据")
@RestController
@RequestMapping("/monitor/data")
public class MonitorController {

    @Autowired
    private IMonitorService monitorService;

    @GetMapping("/data")
    @ApiOperation("根据服务器地址获取服务器监控数据")
    public ServerMonitorData getMonitorDataByAddress(ServerMonitorData serverMonitorData){
        ServerMonitorData monitorDataByAddress = monitorService.getMonitorDataByAddress(serverMonitorData);

        return monitorDataByAddress;
    }

    @GetMapping("/list")
    @ApiOperation("获取运维驾驶舱服务器总览")
    public List<ServerVO> getMonitorDataByAddressList(ServerMonitorData serverMonitorData){
        List<ServerVO> serverVOList = monitorService.getServerMonitorDataList(serverMonitorData);
        return serverVOList;
    }

    @PostMapping("/uploadServerData")
    @ApiOperation("上传监控数据")
    public AjaxResult getServerMonitorData(@RequestBody ServerMonitorDataDTO serverMonitorDataDTO){

        int i = monitorService.insertServerMonitorData(serverMonitorDataDTO);
        if (i > 0) {
            return AjaxResult.success();
        }
        else if (i==0){
            return AjaxResult.error("token有误");
        }else {
            return AjaxResult.error();
        }

    }
}
